package com.yyfax.pay.order.data.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.yyfax.commons.lang.DateUtil;
import com.yyfax.framework.service.CacheService;
import com.yyfax.framework.service.impl.BaseServiceImpl;
import com.yyfax.pay.order.data.dao.QueryTaskDao;
import com.yyfax.pay.order.data.service.QueryTaskService;
import com.yyfax.pay.order.model.po.QueryTaskPO;

/**
 * 查询任务服务实现
 *
 * @author buyi
 * @date 2017-04-12 11:09:15
 * @since 1.0.0
 */
@Service
public class QueryTaskServiceImpl extends BaseServiceImpl implements QueryTaskService {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private QueryTaskDao queryTaskDao;

	public QueryTaskServiceImpl(@Qualifier("payCacheService") CacheService cacheService) {
		super(cacheService);
	}

	@Override
	public QueryTaskPO queryByIdAndMerchantCode(int id, String merchantCode) throws Exception {
		if (id <= 0 && StringUtils.isBlank(merchantCode)) {
			logger.debug("参数 'id' 不能为0，且 'merchantCode' 不能为空 ");
			return null;
		}

		return queryTaskDao.selectByIdAndMerchantCode(id, merchantCode);
	}

	@Override
	public int save(QueryTaskPO po) throws Exception {
		if (po == null) {
			logger.debug("参数po为空，返回-1");
			return 0;
		}

		po.setCreateTime(DateUtil.getCurrentDateTime());

		return queryTaskDao.insert(po);
	}

	@Override
	public void updateTask(QueryTaskPO task) throws Exception {
		if (task == null) {
			return;
		}
		queryTaskDao.update(task);
	}

}
